﻿<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="DoAnPhatTrienPhanMem.Controllers" %>
<%@ Import Namespace="DoAnPhatTrienPhanMem.Models" %>
<%@ Import Namespace="DoAnPhatTrienPhanMem.Constants" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="/Scripts/CommonFunction.js" type="text/javascript"></script>
    <script src="/Scripts/Constant.js" type="text/javascript"></script>
    <link href="/Content/MainStyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function loadForm(store, records) {
            if (records.length > 0) {
                window.TenVien.setText(records[0].data.TenVien);
                //window.TenVien.setText(records[0].data.DiaChi);
                //window.TenVien.setText(records[0].data.NhiemVu);
                //window.TenVien.setText(records[0].data.TenVien);
            }
            else {
            }
        }

        function frmSubmit() {
            window.frmLogin.getForm().submit({
                waitMsg: 'Đang kiểm tra...',
                waitTitle: 'Xác thực quyền đăng nhập',
                clientValidation: true,
                success: CommonFunction.refreshFrame,
                failure: CommonMessenger.failureHandler
            });
        }
    </script>
    <script runat="server">
        private void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var user = "";
                if (Session[Constants.SessionName.UserName] != null) user = Session[Constants.SessionName.UserName].ToString();
                var AccountCtrl = new AccountController();
                var ID = "";
                if (ViewData.ContainsKey("ID")) ID = ViewData["ID"].ToString();
                Ext.Net.MenuItem node;

                if (AccountCtrl.CheckRole(user, "PhongKhoaHoc", "Index"))
                {
                    node = new Ext.Net.MenuItem();
                    node.Text = "Các phòng trực thuộc";
                    node.Listeners.Click.Handler = "CommonFunction.loadPage('PhongKhoaHoc','Index', {IDvien: '" + ID + "'});";
                    MainMenu.Menu.Add(node);
                }
                //node = new Ext.Net.MenuItem();
                //node.Text = "Danh mục cán bộ";
                //node.Listeners.Click.Handler = "CommonFunction.loadPage('CanBo','DanhMucVien', {IDvien: '" + ID + "'});";
                //MainMenu.Menu.Add(node);
                if (AccountCtrl.CheckRole(user, "VienKhoaHoc", "AddOrEdit", ID))
                {
                    node = new Ext.Net.MenuItem();
                    node.Text = "Chỉnh sửa";
                    node.Listeners.Click.Handler = "CommonFunction.loadPage('VienKhoaHoc','AddOrEdit', {ID: '" + ID + "'});";
                    MainMenu.Menu.Add(node);
                }
                if (AccountCtrl.CheckRole(user, "VienKhoaHoc", "Delete"))
                {
                    node = new Ext.Net.MenuItem();
                    node.Text = "Xóa";
                    node.DirectEvents.Click.Url = "/VienKhoaHoc/Delete";
                    node.DirectEvents.Click.Method = HttpMethod.POST;
                    node.DirectEvents.Click.CleanRequest = true;
                    node.DirectEvents.Click.Success = "CommonFunction.loadPage('VienKhoaHoc','Index','');";
                    node.DirectEvents.Click.Failure = "";
                    node.DirectEvents.Click.Confirmation.ConfirmRequest = true;
                    node.DirectEvents.Click.Confirmation.Message = "Chắc chắn xóa viện: " + ViewData["TenVien"].ToString() + " ?";
                    node.DirectEvents.Click.Confirmation.Title = "Xác nhận";
                    var param = new Ext.Net.Parameter("ID", ID);
                    node.DirectEvents.Click.ExtraParams.Add(param);
                    MainMenu.Menu.Add(node);
                }


                if (!String.IsNullOrEmpty(user))
                {
                    frmLogin.Hidden = true;
                    btnLogin.Hidden = true;
                    UserID.Text = user;
                    //UserID.NavigateUrl = "#";
                    UserID.Hidden = false;
                    afterLogin.Hidden = false;
                    var MaCB = AccountCtrl.GetByUserName(user).MaCB;
                    if (MaCB != null)
                    {
                        var CanBoCtrl = new CanBoController();
                        var IDcanbo = CanBoCtrl.GetSoYeuCanBoByMaCB(MaCB.ToString()).ID;
                        UserID.Listeners.Click.Handler = "CommonFunction.loadPage('CanBo','Details',{ID: '" + IDcanbo + "'});";
                    }
                }
            }
        }
    </script>
</head>
<body id="bd" class="fs3">
    <ext:ResourceManager ID="ResourceManager1" runat="server" Locale="vi-VN" CleanResourceUrl="false" />
    <ext:Hidden runat="server" ID="txtID" Text='<%# ViewData["ID"] %>' AutoDataBind="true" />
    <ext:Store ID="storeData" runat="server">
        <Proxy>
            <ext:HttpProxy Url="/VienKhoaHoc/GetByID" />
        </Proxy>
        <Reader>
            <ext:JsonReader Root="data">
                <Fields>
                    <ext:RecordField Name="ID" />
                    <ext:RecordField Name="MaVien" />
                    <ext:RecordField Name="TenVien" />
                    <ext:RecordField Name="DiaChi" />
                    <ext:RecordField Name="NhiemVu" />
                    <ext:RecordField Name="GhiChu" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="ID" Value="#{txtID}.getValue()" Mode="Raw" />
        </BaseParams>
        <Listeners>
            <Load Fn="loadForm" />
        </Listeners>
    </ext:Store>
    <div id="ja-wrapper">
        <div id="ja-container" class="wrap clearfix">
            <div class="main">
                <div class="inner clearfix">
                    <div id="ja-mainbody">
                        <ext:Panel runat="server" Layout="FormLayout" BodyBorder="false" Border="false">
                            <Items>
                                <ext:Label runat="server" ID="TenVien" />
                            </Items>
                        </ext:Panel>
                    </div>
                    <div id="ja-colwrap">
                        <div class="ja-innerpad">
                            <div style="padding: 10px;">
                                <ext:CompositeField runat="server" ID="afterLogin" Hidden="true" LabelWidth="20">
                                    <Items>
                                        <ext:LinkButton runat="server" ID="UserID" />
                                        <ext:LinkButton ID="LinkButton1" runat="server" Text="(Đăng xuất)" NavigateUrl="/Account/Logout" />
                                    </Items>
                                </ext:CompositeField>
                                <ext:FormPanel runat="server" ID="frmLogin" Url="/Account/Login" Border="false" BodyBorder="false"
                                    Layout="FormLayout" AutoHeight="true" AutoWidth="true" LabelWidth="70">
                                    <Items>
                                        <ext:TextField runat="server" ID="Username" FieldLabel="Tài khoản" LabelWidth="50"
                                            AllowBlank="false" />
                                    </Items>
                                </ext:FormPanel>
                            </div>
                            <div style="padding-left: 155px;">
                                <ext:Button ID="btnLogin" runat="server" Text="Đăng nhập">
                                    <Listeners>
                                        <Click Fn="frmSubmit" />
                                    </Listeners>
                                </ext:Button>
                            </div>
                            <div id="Mod1" class="moduletable_menu">
                                <div class="ja-box-ct">
                                    <ul class="menu">
                                        <ext:MenuPanel runat="server" ID="MainMenu" Header="false" Border="false" />
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
